package keye.document_manage.util;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@Component
@Aspect
@Order(1)
public class MultipleDataSourceAspectAdvice {
	
	@Around("execution(* keye.document_manage.dao.mysql.*.*(..))")
	public Object doAround(ProceedingJoinPoint jp)throws Throwable{
		MultipleDataSource.setDatasourceKey(MultipleDataSource.MYSQL);
		MultipleDataSource.setDialect(MultipleDataSource.MYSQL);
		return jp.proceed();
	}
	@Around("execution(* keye.document_manage.dao.sqlserver.*.*(..))")
	public Object doAround2(ProceedingJoinPoint jp)throws Throwable{
		MultipleDataSource.setDatasourceKey(MultipleDataSource.SQLSERVER);
		MultipleDataSource.setDialect(MultipleDataSource.SQLSERVER);
		return jp.proceed();
	}
	
	@Around("execution(* keye.document_manage.dao.sqlite.*.*(..))")
	public Object doAround3(ProceedingJoinPoint jp)throws Throwable{
		MultipleDataSource.setDatasourceKey(MultipleDataSource.SQLITE);
		MultipleDataSource.setDialect(MultipleDataSource.SQLITE);
		return jp.proceed();
	}
}
